// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PlanServiceImp.java

package com.iphaeton.lms.business.plan;

import com.iphaeton.common.helper.Pagination;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.exception.PersistenceException;
import com.iphaeton.lms.business.PersistentServiceSupport;
import com.iphaeton.lms.pojo.plan.Plan;
import com.iphaeton.persistence.IPersistenceService;
import com.iphaeton.persistence.spring.JdbcPService;
import java.util.List;
import org.apache.log4j.Logger;

// Referenced classes of package com.iphaeton.lms.business.plan:
//            IPlanService

public class PlanServiceImp extends PersistentServiceSupport
    implements IPlanService
{

    public PlanServiceImp()
    {
    }

    public Plan findPlanById(String id)
        throws BusinessException
    {
        Plan p = null;
        try
        {
            p = (Plan)hbpservice.get(id, com.iphaeton.lms.pojo.plan.Plan.class);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u901A\u8FC7id\u67E5\u627E\u57F9\u8BAD\u8BA1\u5212\u5931\u8D25!");
        }
        return p;
    }

    public Plan createPlan(Plan p)
        throws BusinessException
    {
        try
        {
            p = (Plan)hbpservice.store(p);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u521B\u5EFA\u6216\u66F4\u65B0\u8BA1\u5212\u65F6\u51FA\u9519!");
        }
        return p;
    }

    public void deletePlan(String id)
        throws BusinessException
    {
        try
        {
            hbpservice.remove(id, com.iphaeton.lms.pojo.plan.Plan.class);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u7269\u7406\u5220\u9664\u57F9\u8BAD\u8BA1\u5212\u5931\u8D25!");
        }
    }

    public void removePlan(Plan p)
        throws BusinessException
    {
        p.setDeleted(new Integer(2));
        try
        {
            hbpservice.store(p);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u903B\u8F91\u5220\u9664\u57F9\u8BAD\u8BA1\u5212\u5931\u8D25!");
        }
    }

    public List findPlanDetail(String id)
        throws BusinessException
    {
        List list = null;
        String sql = "select p.id as id,p.state as state,p.deleted as deleted,p.sn as sn,p.name as pname,o.url as oname,p.comment as comment,";
        sql = sql + "p.creater_userId as userId,p.creater_name as uname,p.release_date as release,p.tag as tag ";
        sql = sql + "from t_plan p inner join t_organize o on p.organize_id = o.id and p.id='" + id + "'";
        try
        {
            list = jdbcpservice.query(sql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u67E5\u8BE2\u8BA1\u5212\u8BE6\u7EC6\u5185\u5BB9\u5931\u8D25!");
        }
        return list;
    }

    public Pagination selectPlan(String userId, Integer state, String row, int pageSize)
        throws BusinessException
    {
        String selectHql = "select count(p) from Plan p  where p.createrId='" + userId + "' and p.deleted!=2";
        String hqlQueryStr = "from Plan p  where p.createrId='" + userId + "' and p.deleted!=2";
        if(state != null && !(new Integer(0)).equals(state))
        {
            selectHql = selectHql + " and state=" + state;
            hqlQueryStr = hqlQueryStr + " and state=" + state;
        }
        if(row != null && !"".equals(row))
            hqlQueryStr = hqlQueryStr + " order by p." + row;
        else
            hqlQueryStr = hqlQueryStr + " order by p.name";
        List list = null;
        try
        {
            list = hbpservice.query(selectHql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("can't find train!");
        }
        int itemCount = list.size() <= 0 ? 0 : ((Integer)list.get(0)).intValue();
        int totalPage = ((itemCount + pageSize) - 1) / pageSize;
        Pagination pageInfo = new Pagination(totalPage, itemCount, pageSize);
        pageInfo.setHqlQueryString(hqlQueryStr);
        return pageInfo;
    }

    public Pagination studentPlan(String org_url, String row, int pageSize)
        throws BusinessException
    {
        String selectHql = "select count(p) from Plan p  where '" + org_url + "' like p.organizeUrl" + "+'%'" + "  and state=2 and deleted!=2 and p.releaseDate is null ";
        String hqlQueryStr = "from Plan p  where '" + org_url + "' like p.organizeUrl" + "+'%'" + "  and state=2 and deleted!=2 and p.releaseDate is null ";
        if(row != null && !"".equals(row))
            hqlQueryStr = hqlQueryStr + " order by p." + row;
        else
            hqlQueryStr = hqlQueryStr + " order by p.name";
        List list = null;
        try
        {
            list = hbpservice.query(selectHql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("can't find train!");
        }
        int itemCount = list.size() <= 0 ? 0 : ((Integer)list.get(0)).intValue();
        int totalPage = ((itemCount + pageSize) - 1) / pageSize;
        Pagination pageInfo = new Pagination(totalPage, itemCount, pageSize);
        pageInfo.setHqlQueryString(hqlQueryStr);
        return pageInfo;
    }

    public List findPageList(Pagination pageInfo)
    {
        List list = null;
        try
        {
            list = getSpecifiedItems(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
        }
        return list;
    }

    private static Logger logger;
    static Class class$0; /* synthetic field */
    static Class class$1; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.business.plan.PlanServiceImp.class.getName());
    }
}
